package cn.kgc.controller;

import cn.kgc.bean.pojo.EpStaff;
import cn.kgc.bean.vo.Result;
import cn.kgc.service.EpStaffService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/*
 *@author wangchangsheng
 *@Date 2023/4/27
 */


@RestController
@RequestMapping("epstaff")
public class EpStaffController {

    @Resource
    private EpStaffService epStaffService;

    @PostMapping("/addEpStaff")
    public Result addEpStaff(@RequestBody EpStaff epStaff){

        boolean flsg=epStaffService.addEpStaff(epStaff);
        if (flsg){
            return Result.success(flsg);
        }else {
            return Result.failure();
        }

    }
    @GetMapping("/getAllInfoEpStaff/{pageFrom}/{pageSize}")
    public Result getAllInfoEpStaff(@PathVariable Integer pageFrom,
                                    @PathVariable Integer pageSize){
        PageHelper.startPage(pageFrom,pageSize);
        List<EpStaff> list = epStaffService.getAllInfoEpStaff();
        PageInfo pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @GetMapping("/getEpStaffBy")
    public Result getEpStaffByAgeAndGenderAndEducationAndDepartment(@RequestParam(defaultValue = "1") Integer pageFrom,
                                                                    @RequestParam(defaultValue = "5") Integer pageSize,
                                                                    @RequestParam(value = "age",required = false )Integer age,
                                                                    @RequestParam(value = "gender",required = false)String gender,
                                                                    @RequestParam(value = "education",required = false)String education,
                                                                    @RequestParam(value = "department",required = false)String department,
                                                                    @RequestParam(value = "staffId",required = false)String staffId,
                                                                    @RequestParam(value = "name",required = false)String name){
        PageHelper.startPage(pageFrom,pageSize);
        List<EpStaff> list = epStaffService.getEpStaffByAgeAndGenderAndEducationAndDepartment(age,gender,education,department,staffId,name);
        PageInfo pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @RequestMapping("/updateEpStaff")
    public Result updateEpStaff(@RequestBody EpStaff epStaff){
        boolean flsg=epStaffService.updateEpStaff(epStaff);
        if (flsg){
            return Result.success(flsg);
        }else {
            return Result.failure();
        }
    }

    @RequestMapping("/delEpStaff")
    public Result delEpStaff(@RequestParam Long id){
        boolean flsg=epStaffService.delEpStaff(id);
        if (flsg){
            return Result.success(flsg);
        }else {
            return Result.failure();
        }
    }


    @RequestMapping("/showStaffInfo")
    public Result showStaffInfo(@RequestParam(defaultValue = "1") Integer pageFrom,
                                @RequestParam(defaultValue = "5") Integer pageSize,
                                @RequestParam(value = "age",required = false )Integer age,
                                @RequestParam(value = "gender",required = false)String gender,
                                @RequestParam(value = "education",required = false)String education,
                                @RequestParam(value = "department",required = false)String department){
        PageHelper.startPage(pageFrom,pageSize);
        List<EpStaff> list = epStaffService.showStaffInfo(age,gender,education,department);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getAge()<=35){
                if(list.get(i).getIllness()==null){
                    int health = 100 - (list.get(i).getViolate()*2);
                    list.get(i).setHealthScore(health);
                }else {
                    int health = 100 - 20 - (list.get(i).getViolate()*2);
                    list.get(i).setHealthScore(health);
                }
            }else {
                if(list.get(i).getIllness()==null){
                    int health = 80 - (list.get(i).getViolate()*2);
                    list.get(i).setHealthScore(health);
                }else {
                    int health = 80 - 20 - (list.get(i).getViolate()*2);
                    list.get(i).setHealthScore(health);
                }
            }

            if(list.get(i).getEducation().equals("大专以下")){
                int fitness = 30 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }else if(list.get(i).getEducation().equals("大专")){
                int fitness = 40 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }else if(list.get(i).getEducation().equals("本科")){
                int fitness = 50 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }else if(list.get(i).getEducation().equals("硕士")){
                int fitness = 60 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }else if(list.get(i).getEducation().equals("硕士以上")){
                int fitness = 70 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }else {
                int fitness = 30 + (list.get(i).getWorkTime()*5) - (list.get(i).getViolate()*2);
                list.get(i).setFitness(fitness);
            }
        }
        PageInfo pageInfo = new PageInfo(list);
        return Result.success(pageInfo);
    }
}
